package com.tledu.production.controller.common;

import com.tledu.production.constant.SessionConstant;
import com.tledu.production.model.device.Device;
import com.tledu.production.model.device.DeviceFault;
import com.tledu.production.model.device.DeviceMaintain;
import com.tledu.production.model.device.DeviceType;
import com.tledu.production.service.device.DeviceFaultService;
import com.tledu.production.service.device.DeviceMaintainService;
import com.tledu.production.service.device.DeviceService;
import com.tledu.production.service.device.DeviceTypeService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author Antg
 * @date 2021/8/15  22:35
 */
@Controller
@AllArgsConstructor
public class CommonController {


    //首页跳转
    @GetMapping(value = {"/", "/index"})
    public String index() {
        return "index";
    }

    //欢迎页跳转
    @GetMapping("/welcome")
    public String welcome() {
        return "welcome";
    }

    //跳转个人信息
    @GetMapping("/person-info")
    public String personInfo() {
        return "other/person-info";
    }

    //退出登录
    @GetMapping("/logout")
    public String logout(HttpSession session) {
        //清空session
        session.setAttribute(SessionConstant.LOGINUSER, null);
        return "redirect:/";
    }

    //跳转权限不够界面
    @GetMapping("/authError")
    public String authException() {
        return "error/auth";
    }

    /***************************** 计划进度 ***********************************/
    @GetMapping(value = {"/plan/CustomerManagement"})
    public String goCustomerManagement() {
        return "plan/CustomerManagement";
    }

    /***************************** 设备管理 ***********************************/


    private DeviceTypeService deviceTypeService;

    //设备台账分页
    @GetMapping("/device/device-list")
    public String goDeviceList() {
        return "device/device-list";
    }

    //设备台账添加
    //增加
    @GetMapping("/device/device-add")
    public String goDeviceAdd() {

        return "device/device-add";
    }

    private DeviceService deviceService;
    //设备台账更新
    @GetMapping("/device/update")
    public String goDeviceUpdate(String deviceId,HttpSession session) {
       Device device = deviceService.findById(deviceId);
       session.setAttribute("Device",device);
        return "device/device-update";
    }

    //设备种类分页
    @GetMapping("/device/device-type-list")
    public String goDeviceTypeList() {
        return "device/device-type-list";
    }

    //设备种类添加
    @GetMapping("/device/device-type-add")
    public String goDeviceTypeAdd() {
        return "device/device-type-add";
    }



    //设备种类更新
    @GetMapping("/device/type/update")
    public String goDeviceTypeUpdate(String deviceTypeId, HttpSession session) {
        DeviceType deviceType = deviceTypeService.findById(deviceTypeId);

        session.setAttribute("DeviceType", deviceType);
        return "device/device-type-update";
    }

    //设备故障分页
    @GetMapping("/device/device-fault-list")
    public String goDeviceFaultList() {
        return "device/device-fault-list";
    }


    //设备故障添加
    @GetMapping("/device/device-fault-add")
    public String goDeviceFaultAdd() {
        return "device/device-fault-add";
    }


    private DeviceFaultService deviceFaultService;
    //设备故障更新
    @GetMapping("/device/fault/update")
    public String goDeviceFaultUpdate(String deviceFaultId, HttpSession session){
        DeviceFault deviceFault = deviceFaultService.findById(deviceFaultId);
        session.setAttribute("DeviceFault",deviceFault);
        return "device/device-fault-update";
    }


    //设备维修分页
    @GetMapping("/device/device-maintain-list")
    public String goDeviceMaintainList() {
        return "device/device-maintain-list";
    }

    //设备种类添加
    @GetMapping("/device/device-maintain-add")
    public String goDeviceMaintainAdd() {
        return "device/device-maintain-add";
    }


    private DeviceMaintainService deviceMaintainService;
    //更新
    @GetMapping("/device/maintain/update")
    public String goDeviceMaintainUpdate(String deviceMaintainId, HttpSession session){
        DeviceMaintain deviceMaintain = deviceMaintainService.findById(deviceMaintainId);
        session.setAttribute("DeviceMaintain",deviceMaintain);
        return "device/device-maintain-update";
    }



    /***************************** 人员监控 ***********************************/

    /***************************** 系统管理 ***********************************/

}
